<template>
  <router-view />
</template>

<script setup lang="ts">
import { onMounted, onUnmounted } from "vue";
import { useSettingsStore } from "./stores/storeSettings";
import { useEntriesStore } from "./stores/storeEntries";
import { useRouter } from "vue-router";
import { useQuasar } from "quasar";

const storeSettings = useSettingsStore();
const entriesStore = useEntriesStore();
const router = useRouter();
const $q = useQuasar();

let cleanupShowSettingsListener: () => void;

onMounted(() => {
  // 加载本地存储
  storeSettings.loadSettings();
  entriesStore.loadEntriesList();

  if ($q.platform.is.electron) {
    // 监听electron菜单
    cleanupShowSettingsListener = window.ipcRenderer.on("show-settings", () => {
      router.push("/settings");
    });
  }
});

onUnmounted(() => {
  if (cleanupShowSettingsListener) cleanupShowSettingsListener();
});
</script>
